﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;


public partial class ManageTaskAdmin : System.Web.UI.Page
{
    DataTable dt;
    protected void Page_Load(object sender, EventArgs e)
    {
        GetTaskGrid();
        LoadTaskType();
        
    }
    protected void btnCreateTask_Click(object sender, EventArgs e)
    {
        
        int gVal = Convert.ToInt32(gvTasksAvailable.SelectedDataKey.Value);
       
        if(gvTasksAvailable.SelectedIndex != -1)
        {
            DataTable dtTask = new DataTable();
            dtTask = DALTask.DisplayTask(gVal);
            if (dtTask.Rows[0][9].ToString() == "1")
            {
                Response.Redirect("~/Admin/CreateTaskAdmin.aspx?TaskId=" + gVal);
            }
        }
    }
    public void GetTaskGrid()
    {
       // DataSet ds = new DataSet();
        DataTable dtDisplayTask = new DataTable();

       // dtDisplayTask.Rows[
        dtDisplayTask = DALTask.GetManageTaskGrid();
        
        gvTasksAvailable.DataSource = dtDisplayTask;
        gvTasksAvailable.DataBind();
     
    }
    private void LoadTaskType()
    {
        ddlTaskType.Items.Clear();
        dt = new DataTable();
        dt = DALTask.GetTaskType();
        ddlTaskType.Items.Add("All");
        ddlTaskType.SelectedIndex = ddlTaskType.Items.IndexOf(ddlTaskType.Items.FindByText("All"));
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            ListItem li = new ListItem();
            li.Text = dt.Rows[i][1].ToString();
            li.Value = dt.Rows[i][0].ToString();
            ddlTaskType.Items.Add(li);
        }

    }
    
    protected void gvTasksAvailable_SelectedIndexChanged(object sender, EventArgs e)
    {
         int gVal = Convert.ToInt32(gvTasksAvailable.SelectedDataKey.Value);
    }
}